import java.util.*;
public class question_3 {
    public static void main(String[] args) {
    // asd

        Runtime r = Runtime.getRuntime();
        long startMem = r.totalMemory(); // 开始Memory
        
        int length = Integer.parseInt(args[0]);
        int[]weight = new int[length];
        int[]value = new int[length];
        int flag = 0;
        for (int i = 1; i <= length; i++) {
            weight[flag++] = Integer.parseInt(args[i]);
        }
        flag = 0;
        for (int i = length+1; i <=length*2 ; i++) {
            value[flag++] = Integer.parseInt(args[i]);
        }
        int bagWeight = Integer.parseInt(args[2*length+1]);
        question_3 question3 = new question_3();
        int maxValue = question3.getMaxValue(weight, value, bagWeight);
        System.out.println(maxValue);
        
        long endMem =r.freeMemory(); // 末尾Memory
        double memUsed = ((double)(startMem-endMem)/1024/1024);
        System.out.printf("%.2f",memUsed);
    }

    -ktg-
}
